package cn.kgc.tangcco.tcbd1011.bigredbook.tbuser.action;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.kgc.tangcco.tcbd1011.bigredbook.tbuser.entity.Tbuser;
import cn.kgc.tangcco.tcbd1011.bigredbook.tbuser.service.UserService;
import cn.kgc.tangcco.tcbd1011.bigredbook.util.Utils;
import cn.kgc.tangcco.tcbd1011.weihuihui.comm.base.BaseServlet;
import cn.kgc.tangcco.tcbd1011.weihuihui.comm.properties.factory.PropertiesFactory;
@WebServlet(name="DoLoginServlet",urlPatterns="/doLogin.action")
public class DoLoginServlet extends BaseServlet {

	private UserService uservice;
	public DoLoginServlet() {
		uservice=(UserService) PropertiesFactory.getValue(Utils.TBUSERSERVICE);
	}
	//��¼����
	public String login(HttpServletRequest request, HttpServletResponse response) {
		String forward = "";
		String password = request.getParameter("password");
		String accout = request.getParameter("accout");
		String requestCode=request.getParameter("requestCode");
		HttpSession session=request.getSession();
		String sessionCode=(String) session.getAttribute("vcode");
		if(requestCode.equals(sessionCode)) {
			Tbuser u=new Tbuser();
			u.setPassword(password);
			u.setAccout(accout);
			
			Tbuser login = this.uservice.login(u);
			
			System.out.println(login);
			if(login!=null) {
				session.setAttribute("redbook", login);
				forward = "main/main";
				
			}else {
				request.setAttribute("msg", "对不起，用户名密码错误!");
				forward ="login";
			}
		}else {
			request.setAttribute("msg", "验证码错误！");
		}
		return forward;
	}
	
	//�˳�ϵͳ�ķ���
		public String doExitSys(HttpServletRequest request, HttpServletResponse response) {
			String forward = "login";
			HttpSession session = request.getSession();
			//���session����Ϣ
			session.invalidate();
			return forward;
		}

}
